package com.rongji.cms.tools.common.exception;

import com.rongji.cms.tools.common.enums.CommonResultCode;
import com.rongji.cms.tools.common.enums.StatusCode;
import lombok.Getter;

/**
 *
 */
@Getter
public class ServiceException extends RuntimeException {
    private int code;
    private String msg;

    // 手动设置异常
    public ServiceException(StatusCode statusCode, String message) {
        // message用于用户设置抛出错误详情
        super(message);
        // 状态码
        this.code = statusCode.getCode();
        // 状态码配套的msg
        this.msg = message;
    }

    public ServiceException(Integer code, String message) {
        // message用于用户设置抛出错误详情
        super(message);
        // 状态码
        this.code = code;
        // 状态码配套的msg
        this.msg = message;
    }

    // 默认异常使用APP_ERROR状态码
    public ServiceException(String message) {
        super(message);
        this.code = CommonResultCode.UNAUTHORIZED.getCode();
        this.msg = message;
    }

}